import { Component,PropsWithChildren } from 'react'
import { View,Text,Image } from '@tarojs/components'
import './index.less'
const baseCls = `legions-main`;
import Taro from '@tarojs/taro';
import UserStore, { InterfaceGitlabToken, InterfaceGitlabUser, InterfaceUser } from '@/store/user.store';
import { Store } from '@/store/core.store';
import { cookies } from '@/utils/cookie';
import {  storage_keys } from '@/constants/storage';
import { routers } from '@/router';
export default class Index extends Component<PropsWithChildren> {
  private get store() {
    const store = Store.getStore(UserStore)
    return store;
  }
  componentWillMount() { }

  componentDidMount() {
    const params = Taro.getCurrentInstance()?.router?.params as { gitlab_token: string,gitlab_user: string,admin_user:string };
    if (params.gitlab_token && params.gitlab_user) { // 通过授权登录跳转进入,记录相关票据
      const _gitlab_token = JSON.parse(params.gitlab_token) as InterfaceGitlabToken
      const _gitlab_user = JSON.parse(params.gitlab_user) as InterfaceGitlabUser;
      const _admin_user = JSON.parse(params.admin_user) as InterfaceUser;
      this.store.setOauthToken(_gitlab_token);
      this.store.setUser(_admin_user);
      this.store.setGitlabUser(_gitlab_user);
      cookies.set(storage_keys.admin_bearer,_admin_user.token);
      Taro.setStorageSync(storage_keys.gitlab_token,_gitlab_token);
      Taro.setStorageSync(storage_keys.gitlab_user,_gitlab_user);
      Taro.setStorageSync(storage_keys.admin_user,_admin_user);
    }
    this.store.authentication();
  }

  componentWillUnmount() { 
    
  }

  componentDidShow() {
  }

  componentDidHide() { }

  onGotoMergeRequest = () => {
    Taro.navigateTo({
      url: routers.merge_request_lst
    })
  }
  onGotoBranch = () => {
    Taro.navigateTo({
      url: routers.branch
    })
  }
  onGotoDeploy = () => {
    Taro.navigateTo({
      url: routers.deploy
    })
  }
  render() {
    return (
      <View className={baseCls}>
        <View className='header'>
          <Text className='title'>集成平台</Text>
          <View className='desc'><Image className='img' src='https://hoolinks-frontend-resources.oss-cn-shenzhen.aliyuncs.com/images/weapp-main.png'></Image></View>
        </View>
        <View className='content'>
          <View className='left'>
            <View className='proj'>
              <Text className='title'>
                项目管理
              </Text>
              <View className='backgroud'></View>
            </View>
            <View className='block mr-apply' onClick={this.onGotoMergeRequest}><Text className='text'>合并申请
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
            <View className='block cr-mr-apply'>
              <Text className='text'>创建申请
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
          </View>
          <View className='right'>
            <View className='block rollback'>
              <Text className='text'>回滚申请
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
            <View className='block deploy' onClick={this.onGotoDeploy}>
              <Text className='text'>发布信息
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
            <View className='block branch' onClick={this.onGotoBranch}>
              <Text className='text'>分支申请
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
            <View className='block my'>
              <Text className='text'>我的申请
                {/* <Text className='badge'>99+</Text> */}
              </Text>
            </View>
          </View>
        </View>
      </View>
    )
  }
}
